<?php

require_once('Dictionary.php');

class DataView extends Dictionary
{

  public function __construct(&$data = null)
  {
    parent::__construct();

    if (! is_null($data)) {
      $this->setData($data);
    }
  }

  public static function getIterator($data)
  {
    $class = get_class($this);
    return new DataViewIterator($data, $class);
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/data/DataHolder#_del($name)
   */
  protected function _del($name)
  {
    if (is_array($this->data)) {
      //if (isset($this->data[$name])) {
        unset($this->data[$name]);
      //}
    }
    elseif (is_a($this->data, 'IDictionary')) {
      $this->data->del($name);
    }

    return $this;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/data/DataHolder#_get($name)
   */
  protected function _get($name, $default = null)
  {
    if (is_array($this->data)) {
      if (isset($this->data[$name])) {
        return $this->data[$name];
      }
    }
    elseif (is_a($this->data, 'IDictionary')) {
      //return $this->data->get($name);
      $args = func_get_args();
      return call_user_func_array(array($this->data, 'get'), $args);
    }
    
    return $default;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/data/DataHolder#_has($name)
   */
  protected function _has($name)
  {
    if (is_array($this->data)) {
      return isset($this->data[$name]);
    }
    elseif (is_a($this->data, 'IDictionary')) {
      return $this->data->has($name);
    }
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/data/DataHolder#_set($name, $value)
   */
  protected function _set($name, $value)
  {
    if (is_array($this->data)) {
      $this->data[$name] = $value;
    }
    elseif (is_a($this->data, 'IDictionary')) {
      $this->data->set($name, $value);
    }

    return $this;
  }

}

?>